package com.jdkreader.jvm;


/**
 * 测试虚拟机是否使用引用计数法判断对象已死
 *
 * -XX:+PrintGCDetails 打印GC信息
 */
public class ReferenceCountingGC {

    public Object instance = null;

    private static final int _1MB = 1024 * 1024;

    private byte[] bigSize = new byte[ 2 * _1MB];

    public static void main(String[] args) {
        ReferenceCountingGC ojbA=new ReferenceCountingGC();
        ReferenceCountingGC ojbB=new ReferenceCountingGC();
        ojbA.instance=ojbB;
        ojbB.instance=ojbA;

        ojbA=null;
        ojbB=null;
        /**
         * ojbA和ojbB存在互相引用，如果使用计数引用法则GC会失败
         */
        System.gc();
    }

}
